<?

	$Tlb = Toolbar();

	global $apps;

	switch($this->cxt[0]){
		case '':
		
			$this->args->icon = 'SmRoot.png';
			$this->args->title = 'Users, Groups, Domains and Databases';
			
			$apps = new jso;
			
			foreach(array('Users', 'Groups', 'Domains', 'Databases') as $c){
				$apps->set($c, new jso(array(
					'name'=>$c,
					'title'=>$c,
					'icon'=>substr($c, 0, -1).'.png',
					'rel'=>strtolower($c),
					'id'=>$c,
					'modpath' => 'SmRoot/0v0r01'
				)));
			}
			
			$apps = json_encode($apps);
		
			break;
			
		case 'users':
		
			$this->args->icon = 'User.png';
			$this->args->title = 'Users';
	
			$qs = "SELECT id, name, class, email FROM users WHERE 1;";
			$al = smdb()->open();
			$q = $al->query($qs);
			if((!$q)||(mysqli_num_rows($q) == 0)) die('no users');
			while($row = mysqli_fetch_array($q, MYSQLI_ASSOC)) $users[$row['id']] = $row;
		
			$apps = serializeUsers($users);
			$Tlb->option('New')->option('User...')->toFunction('NewUser();');
			
			break;
			
		case 'groups':
		
			$this->args->icon = 'Group.png';
			$this->args->title = 'Groups';
	
			$groups = get_groups();
			$apps = serializeGroups($groups);
	
			$Tlb->option('New')->option('Group...')->toFunction('NewGroup();');
		
			break;
			
		case 'domains':

			$this->args->icon = 'Domain.png';
			$this->args->title = 'Domains';
	
			$qs = "SELECT * FROM domains WHERE 1;";
			$al = smdb()->open();
			$q = $al->query($qs);
			if((!$q)||(mysqli_num_rows($q) == 0)) die('no domains?');
			while($row = mysqli_fetch_array($q, MYSQLI_ASSOC)) $doms[$row['id']] = $row;
		
			$apps = serializeDoms($doms);
	
			$Tlb->option('New')->option('Domain...')->toFunction('NewDomain();');
		
			break;
			
		case 'databases':

			$this->args->icon = 'Database.png';
			$this->args->title = 'Databases';

			$apps = new json;
			foreach(glob(ETC_DIR.'/db/*') as $df){
				$n = basename($df);
				$apps->$n = object(
					'name', $n,
					'id', $n,
					'rel', $n,
					'title', $n,
					'icon', 'Database.png',
					'modpath', 'SmRoot/0v0r01'
				);
			}

			$Tlb->option('Operations')->option('New Database')->toFunction('NewDatabase();');
			$Tlb->option('Operations')->option('Duplicate')->toFunction('DuplicateDatabase();', 'Selection.length');
			$Tlb->option('Operations')->option('Delete')->toFunction('DeleteDatabase();', 'Selection.length');
		
			break;
			
		}

	if($this->cxt){
		if($this->cxt !== 'users') $Tlb->option('Go To')->option('Users')->toFunction('goTo("/@root/users");');
		if($this->cxt !== 'groups') $Tlb->option('Go To')->option('Groups')->toFunction('goTo("/@root/groups");');
		if($this->cxt !== 'domains') $Tlb->option('Go To')->option('Domains')->toFunction('goTo("/@root/domains");');
		if($this->cxt !== 'databases') $Tlb->option('Go To')->option('Databases')->toFunction('goTo("/@root/databases");');
	}

?>